home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Devices / CD-ROM / How to Detect a CD / WhereCDs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-18  |  1.8 KB  |  55 lines  |  [TEXT/MPS ]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Sample code demonstrating detecting CD-ROM drives
  5. **
  6. **    by Brian Bechtel, Apple Developer Technical Support
  7. **
  8. **    File:        WhereCDs.c
  9. **
  10. **    Copyright © 1995 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "DTS Sample Code"
  17. **    after having made changes. If you're going to re-distribute the source,
  18. **    we require that you make it clear in the source that the code was
  19. **    descended from Apple Sample Code, but that you've made changes.
  20. */
  21. #include <Devices.h>
  22. #include <TextUtils.h>
  23. #include "WhereCDs.h"
  24.  
  25. // From tech note DV 22, CD-ROM Driver Calls.  Detects drives which
  26. // are using the driver name ".AppleCD" in the range of driver
  27. // reference numbers assigned to the original SCSI bus.  Will not
  28. // handle drives which aren't using a driver named ".AppleCD", nor
  29. // drives on additional SCSI buses.
  30. UInt8 WhereCDs() 
  31.     UInt8        where = 0; /* assume no drives handled at beginning */
  32.     short        scsiAddress; 
  33.     short        drvrRefNum; 
  34.     DCtlHandle    aDCtlEntry; 
  35.     StringPtr    aDriverName; 
  36.     StringPtr    appleDriverName = "\p.AppleCD";
  37.     
  38.     for (scsiAddress = 0; scsiAddress < 7; scsiAddress++) 
  39.     { 
  40.         drvrRefNum = -33 - scsiAddress;
  41.         aDCtlEntry = GetDCtlEntry(drvrRefNum); 
  42.         if (aDCtlEntry != nil) 
  43.         { 
  44.             if ((**aDCtlEntry).dCtlFlags & dRAMBasedMask) 
  45.                 aDriverName = (StringPtr) ((*(DCtlPtr)aDCtlEntry).dCtlDriver+18); 
  46.             else 
  47.                 aDriverName = (StringPtr)((**aDCtlEntry).dCtlDriver+18); 
  48.             if ( EqualString(aDriverName, appleDriverName, false, false) == true ) 
  49.                 where |= (1 << scsiAddress); 
  50.         }
  51.     }
  52.     return where; 
  53. }
  54.